#include<iostream>
#include <algorithm>
#include<vector>
using namespace std;

long long numberOfRightTriangles(vector<vector<int>>& grid) {
    long long count = 0;
    vector<int> zero_column;
    for(int i=0;i<grid.size();i++)
    {
        for(int j=0;j<grid[i].size();j++)
        {
            auto it = find(zero_column.begin(), zero_column.end(), j);
            if(grid[i][j] && it==zero_column.end())
            {
                int c_num = 0;
                int r_num = 0;
                for(int c=0;c<grid[i].size();c++)
                {
                    c_num += grid[i][c];
                }
                if(c_num>1)
                {
                    for(int r=0;r<grid.size();r++)
                    {
                        r_num += grid[r][j];
                    }
                    if(r_num>1)
                    {
                        count += (c_num - 1) * (r_num - 1);
                    }else{
                        zero_column.push_back(j);
                    }
                }else{
                    break;
                }
            }
        }
    }
    return count;        
}

int main()
{
    vector<vector<int>> grid(3);
    cout<<"Enter the elements of the matrix: "<<endl;
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<4; j++)
            {
                int num;
                cin>>num;
                grid[i].push_back(num);
            }
    }
    long long result = numberOfRightTriangles(grid);
    cout<<"The number of right triangles are: "<<result;
    return 0;
}
